define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'enroll/index' + location.search,
                    //index_url: 'enroll/index',
                    add_url: 'enroll/add',
                    edit_url: 'enroll/edit',
                    del_url: 'enroll/del',
                    multi_url: 'enroll/multi',
                    import_url: 'enroll/import',
                    table: 'enroll',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'venue.name', title: __('所属场馆'),operate:false},
                        {field: 'venue_id', title: __('所属场馆'),addclass: 'selectpage', extend:'data-source="ajax/venue"', defaultValue:Config.vid, visible:false},
                        {field: 'activity_id', title: __('活动名'),addclass: 'selectpage', extend:'data-source="ajax/getActivity"', visible:false},
                        {field: 'activity.name', title: __('Activity.name'), operate: false},
                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                       // {field: 'user_id', title: __('User_id')},
                        {field: 'time', title: __('Time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},



                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });
            $("#activity_id").data("params", function (obj) {
                return {custom: {venue_id: $("#venue_id").val()}};
            });
            $("#venue_id").change(function (){
                $("#activity_id_text").val('');

                $("#activity_id").val('');
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});